package com.haixiaoke.saas.enterprise.lock.controller;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.lock.domain.LockFreezeLog;
import com.haixiaoke.saas.lock.service.ILockFreezeLogService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 锁冻结记录Controller
 *
 * @author qixi
 * @date 2024-08-05
 */
@RestController
@RequestMapping("/enterprise/lock/freezeLog")
public class EnterpriseLockFreezeLogController extends BaseController {

    @Autowired
    private ILockFreezeLogService lockFreezeLogService;

    /**
     * 查询锁冻结记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LockFreezeLog lockFreezeLog) {
        startPage();
        List<LockFreezeLog> list = lockFreezeLogService.selectLockFreezeLogList(lockFreezeLog);
        return getDataTable(list);
    }

    /**
     * 导出锁冻结记录列表
     */
    // @PreAuthorize("@ss.hasPermi('lock:freezeLog:export')")
    @Log(title = "锁冻结记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LockFreezeLog lockFreezeLog) {
        List<LockFreezeLog> list = lockFreezeLogService.selectLockFreezeLogList(lockFreezeLog);
        ExcelUtil<LockFreezeLog> util = new ExcelUtil<LockFreezeLog>(LockFreezeLog.class);
        util.exportExcel(response, list, "锁冻结记录数据");
    }

    /**
     * 获取锁冻结记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:freezeLog:query')")
    @GetMapping(value = "/{freezeLogId}")
    public AjaxResult getInfo(@PathVariable("freezeLogId") Long freezeLogId) {
        return success(lockFreezeLogService.selectLockFreezeLogByFreezeLogId(freezeLogId));
    }

    /**
     * 新增锁冻结记录
     */
    @PreAuthorize("@ss.hasPermi('lock:freezeLog:add')")
    @Log(title = "锁冻结记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LockFreezeLog lockFreezeLog) {
        return toAjax(lockFreezeLogService.insertLockFreezeLog(lockFreezeLog));
    }


}
